//---------------------------------------------------------------------
// Author: Keith Hill, jachymko
//
// Description: Base class for all commands which need an Encoding parameter
//
// Creation Date: Dec 9, 2006
//---------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.Text;
using System.Management.Automation;

namespace Pscx.Commands.Internal
{
    public abstract class PscxCmdlet : PSCmdlet
    {
        protected string CmdletName
        {
            get
            {
                CmdletAttribute cmdletAttr = Utils.GetAttribute<CmdletAttribute>(GetType());

                if (cmdletAttr != null)
                {
                    return cmdletAttr.VerbName + "-" + cmdletAttr.NounName;
                }

                return null;
            }
        }

        protected void ValidateEncoding(EncodingParameter encoding)
        {
            if(encoding.IsPresent)
            {
                if(encoding.ToEncoding() == null)
                {
                    ArgumentException exc = new ArgumentException("Unrecognized encoding name " + encoding.ToString(), "encodingName");
                    ThrowTerminatingError(new ErrorRecord(exc, "InvalidArgumentError", ErrorCategory.InvalidArgument, encoding));
                }
            }
        }
    }
}
